/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.erp.server.BPO;

import com.erp.client.DAO.UserBaseInf;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
 *
 * @author Administrator
 */
public class UserRightsBPO extends ActionSupport {

    private UserBaseInf ub;
	private UserBPO userbpo;

	// 必须设置userbpo的setter方法，来访问Spring容器中的UserBp实例
	public void setUserbpo(UserBPO userbpo) {
		this.userbpo = userbpo;
	}

	public String execute() throws Exception {

		if(ub==null){
			return INPUT;
		}
		Integer loginstate;
		loginstate = 0;
		// 获得ActionContext实例，以便访问Servlet API
		ActionContext ctx = ActionContext.getContext();
		// 获得Session
		Map session = ctx.getSession();
		// 判断是否为合法用户，如何合法，则设置权限标识，并返回论坛列表视图，如果不是，则返回到登录界面
		if (userbpo.check(getUb())) {
			loginstate = 1;
			setUb(userbpo.getUb());
			session.put("loginstate", loginstate);
			session.put("user", ub);
			return SUCCESS;
		} else {
			session.put("loginstate", loginstate);
			return LOGIN;
		}
	}

	public UserBaseInf getUb() {
		return ub;
	}

	public void setUb(UserBaseInf ub) {
		this.ub = ub;
	}

}
